package com.erpoa.mapper;

import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.math.BigDecimal;
import java.util.HashMap;

/**
 * @author chenjimin
 * @Title: BatchUtilMapper
 * @ProjectName oaerp
 * @Description: TODO
 * @date 2020/9/229:01
 */
@Mapper
public interface BatchUtilMapper {
    @Select("select distinct FPROCSS FPROCSS, FUNIT FUNIT from dsx5.mg_recmat where forderno = #{fOrderNo} and fmatcode = #{fMatCode}")
    HashMap selectCpByParam(@Param("fOrderNo") String fOrderNo, @Param("fMatCode") String fMatCode);

    @Select("select SFA05,SFA161 from ds2.sfa_file where sfa01 = #{fOrderNo} and sfa03 = #{fMatCode} and sfa08= #{fProcss} and sfa12 = #{fUnit}")
    HashMap selectQpaByPatam(@Param("fOrderNo") String fOrderNo, @Param("fMatCode") String fMatCode, @Param("fProcss") String fProcss, @Param("fUnit") String fUnit);

    @Select(" select nvl(sum(CEIL(ROUND(FPLANQTY * #{qpa},3))),0) as sumqty from dsx5.mg_orderplan where forderno =#{fOrderNo} and fclassjob  in ( 'F','R') and fsendorder = 1 and fisfinishproduced = 'Y'")
    BigDecimal selectCpCeilByParam(@Param("fOrderNo") String fOrderNo, @Param("qpa") BigDecimal qpa);

    @Select("select nvl(sum(ROUND(FPLANQTY * #{qpa}, 3)),0) as sumQty from dsx5.mg_orderplan where forderno = #{fOrderNo} and fclassjob  in ( 'F','R') and fsendorder = 1 and fisfinishproduced = 'Y'")
    BigDecimal selectCpRoundByParam(@Param("fOrderNo") String fOrderNo, @Param("qpa") BigDecimal qpa);

    @Select(" select NVL(SUM(CASE WHEN FOPTYPE = '领料' THEN FRSPQTY  WHEN FOPTYPE = '退料' THEN FRSPQTY * -1 END), 0) AS OVEROUTMAT " +
            " from dsx5.mg_recmatdetail where forderno = #{fOrderNo} and fmatcode = #{fMatCode} ")
    BigDecimal selectOverOutMatByParam(@Param("fOrderNo") String fOrderNo, @Param("fMatCode") String fMatCode);
}
